package com.neusoft.tyut.elm.common.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
 
public class CharaterEncodingFilter extends HttpFilter implements Filter {
	
	private String encoding ="gbk"; //  gb2312, gbk
	
    
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		request.setCharacterEncoding(encoding);
		response.setCharacterEncoding(encoding);
		response.setContentType("application/json;charset=utf-8");
		System.out.println(encoding);
		chain.doFilter(request, response);
	}
 
	public void init(FilterConfig config) throws ServletException {
		this.encoding =config.getInitParameter("encoding");		
	}
}
